package com.moto.controller.user;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.moto.entity.Bolgsort;
import com.moto.entity.Car;
import com.moto.entity.CarBrand;
import com.moto.entity.Category;
import com.moto.entityDto.CarDto;
import com.moto.entityDto.CarSelectDto;
import com.moto.result.Result;
import com.moto.service.IBolgsortService;
import com.moto.service.ICarBrandService;
import com.moto.service.ICarService;
import com.moto.service.ICategoryService;
import com.moto.service.impl.CarServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/moto/car")
@Api(tags = "用户查看车辆接口")
@Slf4j
@CrossOrigin("*")
public class UserCarController {
    @Autowired
    private ICarBrandService carBrandService;
    @Autowired
    private ICarService carService;
    @Autowired
    private ICategoryService categoryService;

    /**
     * 用户端查询摩托品牌并按照ASCII值进行排序
     */
    @GetMapping("/AsciiFindAllCarBrand")
    @ApiOperation("用户端查询摩托品牌并按照ASCII值进行排序")
    public Result<List<CarBrand>> AsciiFindAllCarBrand(){
        QueryWrapper<CarBrand> wrapper = new QueryWrapper<>();
        wrapper.orderBy(true,true,"init");
        List<CarBrand> list = carBrandService.list(wrapper);
        return Result.success(list);
    }

    /**
     * 按照评分排行查询车辆
     */
    @GetMapping("/orderMarkCar")
    @ApiOperation("根据评分排行查询摩托车")
    public Result<List<CarDto>> orderMarkCar(){
        log.info("根据评分排行查询摩托车");
        List<CarDto> list = carService.orderMarkCar();
        return Result.success(list);
    }

    /**
     * 查询所有摩托车标签
     */
    @GetMapping("/findAllBolgSort")
    @ApiOperation("查询摩托车标签")
    public Result<List<Category>> findAllBolgSort(){
        log.info("查询摩托车标签");
        List<Category> list = categoryService.list();
        return Result.success(list);
    }


    /**
     * 用户选择车辆
     */
    @GetMapping("/findCar")
    @ApiOperation("用户挑选车辆接口")
    public Result<List<Car>> findCar(CarSelectDto carSelectDto){
        log.info("用户挑选车辆：{}",carSelectDto);
        List<Car> cars =  carService.userFindCar(carSelectDto);
        return Result.success(cars);
    }


}
